package com.liuyjy.es.wrapper;

import java.util.function.Consumer;

/**
 * @Author liuyjy
 * @Date 2025/2/25 12:07
 * @Description: TODO
 **/
public class EsQueryWrapper<T> extends EsBaseWrapper<T, String, EsQueryWrapper<T>> {
    private static final String MUST = "must";
    private static final String SHOULD = "should";
    private static final String MUST_NOT = "must_not";

    public EsQueryWrapper() {
        this((T)null);
    }

    public EsQueryWrapper(T entity) {
        super.setEntity(entity);
    }

    @Override
    protected EsQueryWrapper<T> self() {
        return this;
    }

    // ========== 逻辑组合 ==========
    @Override
    protected EsQueryWrapper<T> and(Consumer<EsQueryWrapper<T>> consumer) {
        EsQueryWrapper<T> wrapper = new EsQueryWrapper<>();
        consumer.accept(wrapper);
        boolQuery.must(wrapper.boolQuery);
        return self();
    }

    @Override
    protected EsQueryWrapper<T> or(Consumer<EsQueryWrapper<T>> consumer) {
        EsQueryWrapper<T> wrapper = new EsQueryWrapper<>();
        consumer.accept(wrapper);
        boolQuery.should(wrapper.boolQuery);
        return self();
    }

}
